<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>个人注册</title>


    <link rel="stylesheet" type="text/css" href="/css/webbase.css" />
    <link rel="stylesheet" type="text/css" href="/css/pages-register.css" />
</head>
<script>
	function getPhone(){
		var phone = $("#phone").val();
		var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
		if(!myreg.test(phone)){
			alert('请输入有效的手机号码！');
			return;
		}else {
			$.ajax({
				url: "/tbUser/getPhone",
				data: {phone: $("#phone").val()},
				type: "get", //请求方式 get post 默认get
				dataType: "json", //返回值类型 html json text xml
				async: true,//true代表异步请求 false代表同步请求
				success: function (result) {//成功回调函数
					if (result.code == 10000) {
						alert("短信验证码发送成功,请注意查收")
					} else if (result.code == 10011) {
						alert(result.message);
					} else {
						alert("验证码发送失败,请重新尝试")
					}
				},
				error: function (i) {//发生错误回调函数
					alert("异常错误")
				}
			})
		}
	}
	function register(){
		$.ajax({
			url: "/tbUser/getRegister",
			data: $("#formId").serialize(),
			type: "post", //请求方式 get post 默认get
			dataType: "json", //返回值类型 html json text xml
			async: true,//true代表异步请求 false代表同步请求
			success: function (result) {//成功回调函数
				if (result.code == 10000) {
					alert("注册成功")
					location.href="/tbUser/login";
				} else if (result.code == 10008) {//用户名
					alert(result.message);
				} else if (result.code == 10012) {//短信验证码 不正确
					alert(result.message);
				} else if (result.code == 10007) {//密码
					alert(result.message);
				} else if (result.code == 10010) {//已注册过
					alert(result.message);
				} else if (result.code == 10011) {//手机号为空
					alert(result.message);
				} else if (result.code == 10013) {//短信验证码为空
					alert(result.message);
				} else if (result.code == 10014) {//两者密码不一致
					alert(result.message);
				} else {
					alert("注册失败")
				}
			},
			error: function (i) {//发生错误回调函数
				alert("异常错误")
			}
		})
	}
	function unameShow(){
		$.ajax({
			url: "/tbUser/unameShow",
			data:{username:$("#username").val()},
			type: "get", //请求方式 get post 默认get
			dataType: "json", //返回值类型 html json text xml
			async: true,//true代表异步请求 false代表同步请求
			success: function (result) {//成功回调函数
				if (result.code == 10010){
					$("#nameID").text("用户名已存在,请重新输入");
					$("#zhuce").attr("disabled","disabled");
					return;
				}
				$("#nameID").text("");
				$("#zhuce").removeAttr("disabled");
			},
			error: function (i) {//发生错误回调函数
				alert("异常错误")
			}
		})
	}
</script>

<body>
	<div class="register py-container ">
		<!--head-->
		<div class="logoArea">
			<a href="" class="logo-bd"></a>
		</div>
		<!--register-->
		<div class="registerArea">
			<h3>注册新用户<span class="go">我有账号，去<a href="/tbUser/login" target="_blank">登陆</a></span></h3>
			<div class="info">
				<form class="sui-form form-horizontal" id="formId">
					<div class="control-group">
						<label class="control-label">用户名：</label>
						<div class="controls">
							<input type="text" id="username" onblur="unameShow()" name="username" placeholder="请输入你的用户名" class="input-xfat input-xlarge"><span id="nameID" style="background-color:#FF0000 " ></span>
						</div>
					</div>
					<div class="control-group">
						<label  class="control-label">登录密码：</label>
						<div class="controls">
							<input type="password" name="password" placeholder="设置登录密码" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label  class="control-label">确认密码：</label>
						<div class="controls">
							<input type="password" name="password1" placeholder="再次确认密码" class="input-xfat input-xlarge">
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">手机号：</label>
						<div class="controls">
							<input type="text" name="phone"  maxlength="11" minlength="11" placeholder="请输入你的手机号" class="input-xfat input-xlarge" id="phone">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">短信验证码：</label>
						<div class="controls">
							<input type="text" name="code" placeholder="短信验证码" class="input-xfat input-xlarge">  <a onclick="getPhone()">获取短信验证码</a>
						</div>
					</div>
					
					<div class="control-group">
						<label  class="control-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<div class="controls">
							<input name="m1" type="checkbox" value="2" checked=""><span>同意协议并注册《东东商城用户协议》</span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label"></label>
						<div class="controls btn-reg">
							<a class="sui-btn btn-block btn-xlarge btn-danger" id="zhuce"  onclick="register()" target="_blank">完成注册</a>
						</div>
					</div>
				</form>
				<div class="clearfix"></div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机东东商城</li>
				<li>销售联盟</li>
				<li>东东商城社区</li>
			</ul>
			<div class="address">地址：北京市昌平区沙阳路18号 邮编：100000 电话：400-0123-302</div>
			<div class="beian">京ICP备08006666号京公网安备11010888888
			</div>
		</div>
	</div>


<script type="text/javascript" src="/js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="/js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="/js/pages/register.js"></script>
</body>

</html>